if SERVER then
	local function writeRankToFile(ply, rank)
		local ID = string.lower(ply:SteamID())
		local mess = string.lower(file.Read("moocow/users.txt"))
		local lines = string.Explode("\n", mess)
		
		local build = ""
		for i, ln in pairs(lines) do
			local split = string.Explode(" ", ln)
			if table.Count(split) >= 2 then
				if ID != split[1] then
					build = build .. ln .. "\n" 
				end
			end
		end
		
		if rank != "client" then
			build = build .. ID .. " " .. rank .. " " .. ply:GetName()
		end
		
		file.Write("moocow/users.txt", build)
	end

	registerCommand("setaccess", "Sets the player you specify to the rank you choose", function(param)
		local accessMsg = "caller changed target's access to rank"
		if param["settings"]["setaccess_msg"] then
			accessMsg = param["settings"]["setaccess_msg"]
		end
		local accessTable = {}
		accessTable["caller"] = getCaller(param[1])
		local targs = string.Explode(" ", param[3])
		
		local toRank = "client"
		local size = table.Count(targs)
		if size > 1 then
			if not getPlayerByName(targs[size]) then
				toRank = table.remove(targs, size)
			end
		end
		
		local checkRank = getRankByStr(toRank)
		if (not param[1]:IsValid()) || (checkRank && rankIsA(getRank(param[1]), checkRank)) then
			for i, targ in pairs(targs) do
				local plyTarg = getPlayerByName(targ)
				if plyTarg then
					accessTable["target"] = plyTarg:GetName()
					accessTable["rank"] = toRank
					display(param[1], "setaccess", { plyTarg } , parseDisplayMessage(accessMsg, accessTable))
					writeRankToFile(plyTarg, toRank)
				end
			end
		end
	end)
end